package bsh;

import org.objectweb.asm.MethodVisitor;

import bsh.exception.CompilationFailedException;
import bsh.meta.JavaClassWrapper;
import bsh.meta.Scope;
import bsh.meta.TypeWrapper;

/**
 * NodeCompiler para uma lista de expressoes
 * 
 * @author takeshi
 */
public class StatementListNodeCompiler implements NodeCompiler {

    private final BSHStatementExpressionList node;

    private final CompilationUnit unit;

    /**
     *C'tor
     * 
     * @param node node
     * @param unit unit
     */
    public StatementListNodeCompiler(BSHStatementExpressionList node, CompilationUnit unit) {
        super();
        this.node = node;
        this.unit = unit;
    }

    /**
     * {@inheritDoc}
     */
    public void compile(MethodVisitor host, CompilationState state) throws CompilationFailedException {
        for (int i = 0; i < this.node.jjtGetNumChildren(); i++) {
            this.unit.compileNode(this.node.getChild(i), host, state);
            CompilerImpl.popStackIfNeeded(host, state);
        }
        state.assertEmptyStack();
    }

    /**
     * {@inheritDoc}
     */
    public TypeWrapper nodeResultType(Scope scope) throws CompilationFailedException {
        return JavaClassWrapper.VOID_WRAPPER;
    }

}
